
package analisadorsintatico;

/**
 *
 * @author Anderson
 */
public class CommandsGraph {

    private GraphNode root;
    private GraphNode current;
    private int graphBreadth;
    private int graphDepth;
    private int programDepth;

    public CommandsGraph() {
        root = new GraphNode("Start", GraphNode.Tipo.START);
        current = root;
        graphBreadth = 1;
        graphDepth = 1;
    }

    public GraphNode getCurrentNode() {
        return current;
    }
    public void setCurrentNode(GraphNode node) {
        current = node;
    }

    public void setRootAsCurrentNode() {
        current = root;
    }

    public void insert(GraphNode node) {
        current.addNode(node);
    }

    public void display() {
        root.displayNode();
    }

    public void displayLeaves() {
        root.displayLeaves();
    }

    public GraphNode getRoot() {
        return root;
    }
    public int getGraphBreadth() {
        updateGraphBreadth();
        return graphBreadth;
    }

    public int getGraphDepth() {
        updateGraphDepth();
        return graphDepth;
    }

    public int getProgramDepth() {
        return root.getProgramDepth();
    }

    public void updateGraphDepth() {
        graphDepth = root.getDepth();
    }

    private void updateGraphBreadth() {
        int items = 1;
        for(GraphNode node : root.getNodes()) {
            items = node.getBreadth();
//            System.out.println(items);
            if(items > graphBreadth) {
                graphBreadth = items;
            }
        }
        graphBreadth++;
    }
}
